package controller

import (
	"gin-demo/service"
	"gin-demo/tool"

	"github.com/gin-gonic/gin"
)

type ShopController struct {
}

func (sc *ShopController) Router(e *gin.Engine) {
	e.GET("/api/shops", sc.GetShopList)
}

func (sc *ShopController) GetShopList(c *gin.Context) {
	longitude := c.Query("longitude")
	latitude := c.Query("latitude")
	// 没有默认测试给一个
	if longitude == "" || longitude == "undefined" || latitude == "" || latitude == "undefined" {
		longitude = "116.36868"
		latitude = "30.12092"
	}
	ss := service.ShopService{}
	shops := ss.ShopList(longitude, latitude)
	if len(shops) != 0 {
		tool.Success(c, shops)
		return
	}

	tool.Failed(c, "数据获取失败")
}
